/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jsf;

import ejb.Customer;
import ejb.Account;
import bean.CustomerBean;
import bean.AccountBean;
import javax.faces.model.ListDataModel;
/**
 *
 * @author longdm0708l
 */

public class CustomerController {
    /** Creates a new instance of CustomerController */
    public CustomerController() {
        customerDataModel = new ListDataModel();
    }

    private Customer currentCustomer;
    private Account currentAccount;
    private ListDataModel customerDataModel;

    public ListDataModel getCustomerDataModel() {
        CustomerBean cb = new CustomerBean();
        customerDataModel.setWrappedData(cb.getAllCustomer());
        return customerDataModel;
    }

    public String viewCustomer(){
        currentCustomer = (Customer)customerDataModel.getRowData();
        return "customerDetail";
    }

    public String editCustomer()
    {
        CustomerBean cb = new CustomerBean();
        cb.editCustomer(currentCustomer);
        return "customerManager";
    }

    public String deleteCustomer()
    {
        currentCustomer = (Customer)customerDataModel.getRowData();
        CustomerBean cb = new CustomerBean();
        cb.removeCustomer(currentCustomer);
        return "";
    }

    public Account getCurrentAccount() {
        return currentAccount;
    }


    public Customer getCurrentCustomer() {
        return currentCustomer;
    }

    public String newCustomer()
    {
        AccountBean ab = new AccountBean();
        ab.createAccount(currentAccount);
        return "success";
    }

    public String toNewCustomer()
    {
        currentAccount = new Account();
        return "newCustomer";
    }

    public String cancel()
    {
        return "index";
    }

    public String cancel2()
    {
        return "_customerUser";
    }

    public String toCustomerEdit()
    {
        currentCustomer = (Customer)customerDataModel.getRowData();
        return "customerEdit";
    }
    
    public String to_customerProfile()
    {
        currentAccount = new Account();
        currentCustomer = new Customer();
        return "_customerProfile";
    }
}
